/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arthurh.android.BdeInfo.connection;
import com.arthurh.android.BdeInfo.*;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import android.widget.ProgressBar;
import android.widget.EditText;
import android.content.Context;
/**
 *
 * @author arthur
 */
public class ConnectionActivity extends Activity
{
    private EditText idIut;
    private EditText pass;
    private ProgressBar loading;
    private Connection conn;
    private Context context;
    public static final int RESULT_Main = 1;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        
        super.onCreate(savedInstanceState);
        conn = new Connection();
        context = this.getBaseContext();
        this.setTitle("BdeInfo - Connexion");
        setContentView(R.layout.connect);
        idIut = (EditText) findViewById(R.id.idIut);
        pass = (EditText) findViewById(R.id.pass);
        loading = (ProgressBar) findViewById(R.id.loading);
        
        ((Button)findViewById(R.id.connexion)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                loading.setVisibility(v.VISIBLE);
                if(conn.connSite(idIut.getText().toString(), pass.getText().toString(), context)){
                    Toast.makeText(ConnectionActivity.this, "Vous êtes connecté !", Toast.LENGTH_LONG).show();
                    finish();
                }else{
                    loading.setVisibility(v.INVISIBLE);
                    Toast.makeText(ConnectionActivity.this, "Identifiant/Mot de passe incorrecte !", Toast.LENGTH_LONG).show();
                }
                
            }
        });
        ((Button)findViewById(R.id.create)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
               startActivity(new Intent(ConnectionActivity.this, Inscription.class));
            }
        });
    }
    
}
